
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>怡臣优选3.0-地址定位</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/css/address.css">
    <style type="text/css">
        html{height:500px}
        body{height:500px;margin:0px;padding:0px}
        #container{height:50%}
    </style>
	<include file="Public/common_js"/>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nHuRBXYat91Wk1jCF4LkgxBMq37LGmhh"></script>
</head>

<body>
<div id="container"></div>

<div class="warp">
    <div class="location-box" >
        <div  class="location-result pdLR">
            <ul id="location-result">
            </ul>
        </div>
    </div>
</div>
<input type="hidden" id="store_lnt" name="store_lnt">
<input type="hidden" id="store_lat" name="store_lat">
<input type="hidden" id="address_detail" name="address_detail">
<script type="text/javascript">
	require(['addressLocation']);
</script>
<script type="text/javascript">

    var map = new BMap.Map("container");
    map.enableScrollWheelZoom(true);
    var markerTmp,lng="106.535645",lat="29.61527";
    if(lng != '' && lat != ''){
        map.centerAndZoom(new BMap.Point(lng,lat),17);
        var marker = new BMap.Marker(new BMap.Point(lng,lat));  // 创建标注
        markerTmp = marker;
        map.addOverlay(marker); //将标注添加到地图中
    }else{
        map.centerAndZoom("<{$area_baidu_map}>",15); //设置地图元素的可视层
    }
    _getLocation(lng,lat);

    map.addEventListener("click", function(e) {
        //alert("您点击了地图。");
        if (markerTmp != '') {
            map.removeOverlay(markerTmp);
        }

        lng = e.point.lng;
        //document.getElementById("store_lnt").value = lng;
        lat = e.point.lat;
        //document.getElementById("store_lat").value = lat;
        //在地图上面描点
        var marker = new BMap.Marker(new BMap.Point(lng, lat));  // 创建标注
        markerTmp = marker;
        map.addOverlay(marker);
        var gc = new BMap.Geocoder();
        //获取地址的数据地址
        var pt = e.point;
        gc.getLocation(pt, function (rs) {
            var addComp = rs.addressComponents;

            var site = addComp.city + addComp.district + addComp.street ;
            var _html = mapSite(site,rs);
            //console.log(_html);
            $('#location-result').html(_html);
            //address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
            //document.getElementById("address_detail").value = address;
        });
    });
    //列表
    //mapSite('106.535645','29.61527');
    //$aaa = mapSite('106.535645','29.61527');
    //console.log($aaa);
    function _getLocation(lng,lat){
        //alert(lng);
        var _pt = new BMap.Point(lng,lat);
        //var _pt = _adds[index];
        //console.log(_pt);
        var gc = new BMap.Geocoder();
        gc.getLocation(_pt, function (rs) {
            var addComp = rs.addressComponents;

            var site = addComp.city + addComp.district + addComp.street ;
            var _html = mapSite(site,rs);
            //console.log(_html);
            $('#location-result').html(_html);
        });
    }
    /*
    获取周边位置
     */
    function mapSite(site,rs){
        //console.log(rs);
        var ul=$('#location-result');
        ul.empty();
        var surroundingPois = rs.surroundingPois;
        //console.log(surroundingPois);
        //var html = '';
        for (var i=0;i<surroundingPois.length;i++){
            var _lng = surroundingPois[i].point.lng;
            var _lat = surroundingPois[i].point.lat;
            var _site = site+surroundingPois[i].address;
            if(i == 0){
                var dom_label = $('<label>').html('当前');
                var dom_p1 = $('<p>').html(surroundingPois[i].title).append(dom_label);
                var dom_p2 = $('<p>').html(_site);
                $('<li>').attr('lng',_lng).attr('lat',_lat).attr('site',_site).append(dom_p1).append(dom_p2).on('click',function(){

                    window.location.href="{:U('Baidu/mapDeposit')}?lng="+$(this).attr('lng')+"&lat="+$(this).attr('lat')+"&site="+$(this).attr('site')+"&fun={$fun}";
                }).appendTo(ul);
            }else{
                dom_p1 = $('<p>').html(surroundingPois[i].title);
                dom_p2 = $('<p>').html(_site);
                $('<li>').attr('lng',_lng).attr('lat',_lat).attr('site',_site).append(dom_p1).append(dom_p2).on('click',function(){
                    //alert(_lng);
                    window.location.href="{:U('Baidu/mapDeposit')}?lng="+$(this).attr('lng')+"&lat="+$(this).attr('lat')+"&site="+$(this).attr('site')+"&fun={$fun}";
                }).appendTo(ul);
            }
        }
    }



    /*gc.getLocation(_pt, function (rs) {
        var ul=$('#location-result');
        var addComp = rs.addressComponents;
        var site = addComp.city + addComp.district + addComp.street ;
        var surroundingPois = rs.surroundingPois;
        for (var i=0;i<surroundingPois.length;i++){
            var _lng = surroundingPois[i].point.lng;
            var _lat = surroundingPois[i].point.lat;
            var _site = site+surroundingPois[i].address;
            var domSpan=$('<span>').html(123);
            var domp=$('<p>').append(domSpan);
            $('<li>').addClass('address').append(domp).on('click',function(){
                $(this).data('title',_site);
                console.log($(this).data('title'));
            }).appendTo(ul);
        }

        //var _html = mapSite(site,rs);
        //alert(_html);
        //$('#location-result').html(_html);

    });*/


</script>
</body>
</html>